-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL-decoding query and form parameters + decoding FormData
#392
Conversation
thank you @pbrinkmeier ! I'll take a look soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good but just a minor comment in ScottySpec, I think we should reuse the implementation from hspec-wai (unless I'm missing something).
Edit: Also could you please add a line in the Changelog describing your changes?
|
||
describe "formParam" $ do | ||
let | ||
postForm p bdy = request "POST" p [("Content-Type","application/x-www-form-urlencoded")] bdy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I got the implementation from.
I added the changelog entry |
e4ef8ff
to
5ceee31
Compare
Fixed the conflict in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to understand how much does the new function overlap in functionality with formParams
and related. Also, I'm not sure using body
is a good idea (depends on whether it respects #147 or not)
Web/Scotty/Action.hs
Outdated
-- status is set to 400 and an exception is thrown. | ||
-- | ||
-- NB : Internally this uses 'body'. | ||
formData :: (FromForm a, MonadIO m) => ActionT m a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relationship between this and formParam(s) ?
If the only difference is which form encoding they can handle, we might want to extend the current functions rather than introducing a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web/Scotty/Action.hs
Outdated
-- NB : Internally this uses 'body'. | ||
formData :: (FromForm a, MonadIO m) => ActionT m a | ||
formData = do | ||
b <- body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does body
preserve the request body across calls to next
? see #308
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure what the desired behavior is, I assumed this was "right" because of the way jsonData
is written :)
Should I add a test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! (beautiful diagram btw, how did you make it?)
Basically this "lazier" parsing of request bodies (underneath the implementation of files
, formParams
etc.) is what I introduced in #369 and I think it would make sense for form parameters too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diagram is made using plant UML, basically a text-based UML tool. Getting the call graph from Haskell isn't automatic tho, I did that by hand. Below is the source code for it.
@startuml
skinparam dpi 300
hide members
hide circle
package "Web.Scotty.Action" {
formParams -down-> "Web.Scotty.Internal.Types.formParamsAndFilesWith"
formData -down-> body
body -down-> "Web.Scotty.Internal.Types.envBody"
}
package "Web.Scotty.Internal.Types" {
formParamsAndFilesWith -left-> envFormDataAction
envFormDataAction -down-> "Web.Scotty.Body.getFormParamsAndFilesAction"
envBody -down-> Web.Scotty.Body.getBodyAction
}
note top of Web.Scotty.Internal.Types.envFormDataAction
Initialized by mkEnv
end note
note top of Web.Scotty.Internal.Types.envBody
Initialized by mkEnv
end note
package "Web.Scotty.Body" {
getFormParamsAndFilesAction -down-> getBodyAction
getFormParamsAndFilesAction -right-> parseRequestBodyExBS
parseRequestBodyExBS -down-> "Network.Wai.Parse.sinkRequestBodyEx"
}
package "Network.Wai.Parse" {
sinkRequestBodyEx -down-> conduitRequestBodyEx
conduitRequestBodyEx -down-> "Network.HTTP.Types.parseSimpleQuery"
}
package Network.HTTP.Types {
parseSimpleQuery -right-> parseQuery
parseQuery -right-> urlDecode
}
@enduml
I am still not entirely sure how to go forward with |
I think rewriting it in terms of formParams would be a great way forward! |
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Just a changelog conflict to resolve and a comment to clarify why an implementation looks the way it does.
Also add some tests for formData
Also move postForm helper function to top level
Add `unordered-containers` dependency for working with `HashMap`
bc4286a
to
cbdbe4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @pbrinkmeier , all good! 👍
Hiya, first time contributor.
This PR adds
queryParam
andformParam
formData
action from Add for decoding x-www-form-urlencoded data #216Let me know if this looks good to you guys or if I need to change anything.
closes #321 , closes #170 .